package com.ruoyi.approval.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.approval.dto.ExecutionRequestsDto;
import com.ruoyi.approval.form.AddExecutionRecordsForm;
import com.ruoyi.approval.param.AddExecutionRecordsParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.approval.domain.AExecutionRecords;
import com.ruoyi.approval.service.IAExecutionRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 申请执行记录Controller
 *
 * @author ruoyi
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/records")
public class AExecutionRecordsController extends BaseController
{
    @Autowired
    private IAExecutionRecordsService aExecutionRecordsService;

    /**
     * 查询申请执行记录列表
     */
    @RequiresPermissions("approval:records:list")
    @GetMapping("/list")
    public TableDataInfo list(AExecutionRecords aExecutionRecords)
    {
        startPage();
        List<AExecutionRecords> list = aExecutionRecordsService.selectAExecutionRecordsList(aExecutionRecords);
        return getDataTable(list);
    }

    /**
     * 导出申请执行记录列表
     */
    @RequiresPermissions("approval:records:export")
    @Log(title = "申请执行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AExecutionRecords aExecutionRecords)
    {
        List<AExecutionRecords> list = aExecutionRecordsService.selectAExecutionRecordsList(aExecutionRecords);
        ExcelUtil<AExecutionRecords> util = new ExcelUtil<AExecutionRecords>(AExecutionRecords.class);
        util.exportExcel(response, list, "申请执行记录数据");
    }

    /**
     * 获取申请执行记录详细信息
     */
    @RequiresPermissions("approval:records:query")
    @GetMapping(value = "/{approvalRequestId}")
    public AjaxResult getInfo(@PathVariable("approvalRequestId") Long approvalRequestId)
    {
        ExecutionRequestsDto data = aExecutionRecordsService.selectAExecutionRecordsById(approvalRequestId);
        return success(data);
    }

    /**
     * 新增申请执行记录
     */
    @RequiresPermissions("approval:records:add")
    @Log(title = "申请执行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddExecutionRecordsForm form)
    {
        return toAjax(aExecutionRecordsService.insertAExecutionRecords(BeanUtil.toBean(form, AddExecutionRecordsParam.class)));
    }

    /**
     * 修改申请执行记录
     */
    @RequiresPermissions("approval:records:edit")
    @Log(title = "申请执行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AExecutionRecords aExecutionRecords)
    {
        return toAjax(aExecutionRecordsService.updateAExecutionRecords(aExecutionRecords));
    }

    /**
     * 还车接口
     */
    @RequiresPermissions("approval:records:remove")
    @Log(title = "申请执行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{approvalRequestId}")
    public AjaxResult remove(@PathVariable Long approvalRequestId)
    {
        return toAjax(aExecutionRecordsService.deleteAExecutionRecordsById(approvalRequestId));
    }
}
